/**
 * 旋转数组
 * https://leetcode-cn.com/problems/rotate-array/
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
 var rotate = function(nums, k) {
  
      let len = nums.length
      let offset = k%len
      if(!offset || len === offset){
        return nums
      }
      // 全部颠倒
      let l = 0
      let r = len-1
      let tmp
      while(l<=r){
        tmp = nums[l]
        nums[l] = nums[r]
        nums[r] = tmp
        l++
        r--
      }

      //从offset位置分割，各自颠倒
      // 左边部分
      l = 0
      r = offset-1
      while(l<=r){
        tmp = nums[l]
        nums[l] = nums[r]
        nums[r] = tmp
        l++
        r--
      }
      // 右边部分
      l = offset
      r = len-1
      while(l<=r){
        tmp = nums[l]
        nums[l] = nums[r]
        nums[r] = tmp
        l++
        r--
      }
};


let nums = [1,2,3,4,5,6,7],k = 3

rotate(nums,k)
console.log(nums)

//================v2要点总结===============
/**
 * 1.因为之前做过，印象中解题方式是两次翻转，结合双指针，该版本尝试一下
 */